import pymysql
import pandas as pd
import numpy as np

df = pd.read_csv('dataset.csv')
connection = pymysql.connect(host='localhost', user='root', password='123456', db='test')
cursor = connection.cursor()
cursor.execute(
    '''
        CREATE TABLE IF NOT EXISTS dataset(
        id INT PRIMARY KEY AUTO_INCREMENT,
        name VARCHAR(255),
        age INT,
        nationality VARCHAR(255),
        education VARCHAR(255),
        gender VARCHAR(255)
        )
    '''
)
for i, row in df.iterrows():
    sql = "INSERT INTO dataset (name, age, nationality, education, gender) VALUES (%s, %s, %s, %s, %s)"
    cursor.execute(sql, (row['name'], row['age'], row['nationality'], row['education'], row['gender']))
connection.commit()
cursor.close()
connection.close()
print('Data inserted successfully')
